<template>
  <div>
    <el-card>
      <el-table
      max-height="500"
      :data="bannerList"
      style="width: 100%">
      <el-table-column
        label="Banner"
        width="300"
        height="100">
        <template slot-scope="scope">
          <el-image :src="scope.row.url"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button> -->
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
  </div>
</template>

<script>
import { getBanner, deleteData } from "../../utils/api";
export default {
  data() {
    return {
      bannerList: [],
      params: {
        type: "banner"
      },
      deleteParams: {
        type: "banner",
        id: ""
      }
    };
  },
  created() {
    this.getBannerList();
  },
  methods: {
    // 删除指定ID数据
    handleDelete(index, row) {
      this.deleteParams.id = row.img_id;
      this.$confirm("确认删除？").then(() => {
        deleteData(this.deleteParams).then(res => {
          res.status === "200" && this.$message("删除成功");
          this.bannerList = res.data.results;
        });
      });
    },
    // 获取banner图片
    getBannerList() {
      getBanner(this.params).then(res => {
        this.bannerList = res.data.results;
      });
    }
  }
};
</script>

<style>

</style>
